<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<link href="../css/style_wln.css" rel="stylesheet" type="text/css">
<script type="text/javascript">

    var value = window.location.href;
    var arr = value.substring(value.lastIndexOf('?') + 1,value.length).split('&');
    var info = new Array();
    for(var i = 0; i < arr.length; i++){
        info[arr[i].split('=')[0]] = arr[i].split('=')[1];
    }

    function func1(){
        var height = document.body.clientHeight;
        document.getElementById('main_content').style.height = height - 100;

        //加载数据
        //访问mysql，调取数据后，解析赋值

        //先声明一个异步请求对象
        var xmlHttpReg = null;
        if (window.ActiveXObject) {//如果是IE
            xmlHttpReg = new ActiveXObject("Microsoft.XMLHTTP");
        } else if (window.XMLHttpRequest) {
            xmlHttpReg = new XMLHttpRequest(); //实例化一个xmlHttpReg
        }

        var q = info['query'];
        if(q==null){
            document.getElementById('jiemeng_content').value = '简述你的梦境';
        }else{
            document.getElementById('jiemeng_content').value = decodeURI(q);
        }


        //如果实例化成功,就调用open()方法,就开始准备向服务器发送请求
        if (xmlHttpReg != null) {
            xmlHttpReg.open("get", "../behind_manage/jm.php?q="+q, true);
            xmlHttpReg.send(null);
            xmlHttpReg.onreadystatechange = doCallBack; //设置回调函数
        }

        function doCallBack(){
            if(xmlHttpReg.readyState == 4){
                if (xmlHttpReg.status == 200) {//200代表执行成功
                    //将xmlHttpReg.responseText的值赋给ID为resText的元素
                    //document.getElementById("resText").innerHTML = xmlHttpReg.responseText;
                    var result = xmlHttpReg.responseText;
//                    alert(result);
                    eval("var json= " + result);
                    var jm_content = '';
                    for(var i = 0;i < json.result.length; i++){
                        jm_content += '<div class="jm_record"><p>'+(i+1)+':'+json.result[i].title+'</p><p class="color_glod">&nbsp;&nbsp;'+json.result[i].des+'</p></div>'
                    }
                    jm_content +='<div style="height: 1550px;"></div>'
                    document.getElementById('jm_content').innerHTML = jm_content;
//                    alert("data--"+json);
                }
            }
        }
    }

    function jiemei_content(){
        var jiemeng_content = document.getElementById("jiemeng_content");
        if(jiemeng_content.value=="简述你的梦境.."){
            alert("请输入正确内容!!!");
        }else{
            window.location.href='jiemeng_content.html?query='+jiemeng_content.value;
        }
    }

    window.onload=func1;
</script>
<body>
    <div class="title red_write">
        <p><a href="wln.html">返回</a></p>
        <p>解梦</p>
    </div>
    <div class="main_content" id="main_content">
        <div id="search_line" class="search_line">
            <input type="text" value="简述你的梦境.." id="jiemeng_content" onfocus="this.value=''" onblur="if(this.value==''){this.value='简述你的梦境..'}" />
            <p onclick="jiemei_content()" class="color_transparent">点击</p>
        </div>
        <div id="jm_content">
        </div>
    </div>
</body>
</html>